/**
 * 
 */
package com.bolbachchan.blog.validator.posts;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

/**
 * @author Chaitanya
 * 
 */
@Component
public class UserPostsValidator implements Validator {

    /*
     * (non-Javadoc)
     * @see org.springframework.validation.Validator#supports(java.lang.Class)
     */
    @Override
    public boolean supports(Class<?> clazz) {
	return clazz.isAssignableFrom(UserPostsValidator.class);
    }

    /*
     * (non-Javadoc)
     * @see org.springframework.validation.Validator#validate(java.lang.Object,
     * org.springframework.validation.Errors)
     */
    @Override
    public void validate(Object target, Errors errors) {
	// NewPostForm form = (NewPostForm) target;
	ValidationUtils.rejectIfEmpty(errors, "postTitle", "Please Title your post");
	ValidationUtils.rejectIfEmpty(errors, "postContent", "Please write a post to save it");
    }

}
